package com.xbfinal.eduservice.controller.front;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xbfinal.commonUtils.Result;
import com.xbfinal.eduservice.entity.EduCourse;
import com.xbfinal.eduservice.entity.EduTeacher;
import com.xbfinal.eduservice.service.EduCourseService;
import com.xbfinal.eduservice.service.EduTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Title: TeacherFrontController
 * @Author 笑霸fianl
 * @Package com.xbfinal.eduservice.controller.front
 * @Date 2023/3/5 14:11
 * @描述: 前台讲师
 */

@RestController
@RequestMapping("/eduservice/teacherfront")
@Api(description = "讲师前台")
@Slf4j
public class TeacherFrontController {

    @Autowired
    private EduTeacherService eduTeacherService;
    @Autowired
    private EduCourseService eduCourseService;

    @ApiOperation("分页查找讲师")
    @PostMapping("getTeacherFrontList/{page}/{limit}")
    public Result getTeacherFrontList(@PathVariable("limit") Long limit,
                                      @PathVariable("page") Long page){
       Map<String,Object> Map = eduTeacherService.getTeacherFrontList( limit,page);

        //返回所有数据
        return Result.ok().addData(Map);
    }



    @ApiOperation("讲师详情页面")
    @GetMapping("getTeacherFrontInfo/{id}")
    public Result getTeacherFrontInfo(@PathVariable String id){

        //查询讲师的基本信息
        EduTeacher teacher = eduTeacherService.getById(id);

        //根据讲师id查询课程
        QueryWrapper<EduCourse> eduCourseQueryWrapper = new QueryWrapper<>();
        eduCourseQueryWrapper.eq("teacher_id",id);
        List<EduCourse> list = eduCourseService.list(eduCourseQueryWrapper);

        log.info(list.toString());
        return Result.ok().add("teacher",teacher).add("courseList",list);
    }
}
